
var globalContextMenu;
var globalPalette;
var globalColorGrid;
var alreadyrunflag=0 //flag to indicate whether target function has already been run

Event.observe( document, 'contextmenu', stub, true );        // IE needs it

function stub( event )
{
  var element = Event.element( event );
  var bd = $( document.body )
  var r = Element.descendantOf( element, bd ) || ( element == bd ) || ( element.tagName == 'HTML' );
  if( ! r || ( element.id == 'context_menu' ) )
  {
    Event.stop( event );
    return false;
  }  
  return true;
}

function initPage( afterAll )
{
  globalContextMenu = new ContextMenu();
  globalContextMenu.hide();
  globalColorGrid = initColorGrid();
  globalPalette = initPalette( globalColorGrid );

  Try.these
  (
    function()  // FF
    {
      document.addEventListener( "DOMContentLoaded", 
        function()
        {
          alreadyrunflag=1; 
          afterAll();
        }, false)
    },
    function()   // IE
    {
      document.write('<script type="text/javascript" id="contentloadtag" defer="defer" src="javascript:void(0)"><\/script>');
      $("contentloadtag").onreadystatechange =
      function()
      {
        if( this.readyState == "complete" )
        {
          alreadyrunflag = 1;
          afterAll();
        }
      }
    }
  );
}
